package socket;

import java.net.ServerSocket;
import java.net.Socket;

import partida.sala.Sistema;

public class ServidorTCP {
	
	private String codificacao = "UTF-8"; //codificacao de caracteres adotada nas mensagens transmitidas
	
	public static void main(String[] args) {
		ServidorTCP servidor = new ServidorTCP();
		try{
			servidor.start();
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void start() throws Exception{
		ServerSocket serverSocket = new ServerSocket(6654);
		System.out.println("Servidor em execucao");
		Sistema sistema = new Sistema();
		while(true){
			Socket clientSocket = serverSocket.accept();
			Socket socketRetorno = serverSocket.accept();
			Thread thread = new Thread(new GerenciadorDoCliente(clientSocket, socketRetorno, sistema, codificacao));
			thread.start();
			System.out.println("Iniciada conexao com o IP " + clientSocket.getInetAddress().getHostAddress());
		}
	}
}
